import com.syx.client.Service;
import com.syx.client.User;
import org.apache.cxf.endpoint.Client;
import org.apache.cxf.frontend.ClientProxy;
import org.apache.cxf.interceptor.LoggingInInterceptor;
import org.apache.cxf.interceptor.LoggingOutInterceptor;
import org.apache.cxf.jaxws.JaxWsProxyFactoryBean;
import org.apache.cxf.transport.http.HTTPConduit;
import org.apache.cxf.transports.http.configuration.HTTPClientPolicy;

import java.util.Collections;

/**
 * Author whh
 * Date 2023/12/07/ 22:58
 * <p></p>
 */
public class MainTest2 {



    public static void fn(){



    }

    public static void main(String[] args) {

        String address = "http://127.0.0.1:8080/primal/cxf/api/Service";
        // 代理工厂
        JaxWsProxyFactoryBean jaxWsProxyFactoryBean = new JaxWsProxyFactoryBean();
        // 设置代理地址
        jaxWsProxyFactoryBean.setAddress(address);
        // 设置接口类型
        jaxWsProxyFactoryBean.setServiceClass(com.syx.client.Service .class);

        jaxWsProxyFactoryBean.setInInterceptors(Collections.singletonList(new LoggingInInterceptor()));
        jaxWsProxyFactoryBean.setOutInterceptors(Collections.singletonList(new LoggingOutInterceptor()));
        // 创建一个代理接口实现
        Service  xmlEndPoint = (com.syx.client.Service ) jaxWsProxyFactoryBean.create();

        Client proxy = ClientProxy.getClient(xmlEndPoint);
        HTTPConduit conduit = (HTTPConduit) proxy.getConduit();
        HTTPClientPolicy policy = new HTTPClientPolicy();
        policy.setConnectionTimeout(5000);
        policy.setReceiveTimeout(5000);
        conduit.setClient(policy);

        com.syx.client.User  user = new User ();
        user.setUserName("ls");
        String service = xmlEndPoint.sayHello(user);

        System.out.println(service);

    }
}
